define(["require","jquery","notify_comm","String"],
    function(require,$,notify_comm,String){

    var init =function () {
        _login();
        _layout();
    }

    var _login = function () {
        $("#loginBtn").on("click",function () {
            if(!$("input[name=userName]").val()){
                notify_comm.errorMSG({"message":"请输入用户名"});
                return;
            }
            if(!$("input[name=userPwd]").val()){
                notify_comm.errorMSG({"message":"请输入密码"});
                return;
            }
            if(!$("input[name=clientCode]").val()){
                notify_comm.errorMSG({"message":"请输入租户"});
                return;
            }
            $.ajax({
                url: "/login/loginUser",
                type: "POST",
                async: false,
                dataType: "text",
                data: {"userName": $("input[name=userName]").val(),"userPwd":$("input[name=userPwd]").val(),"clientCode":$("input[name=clientCode]").val()},
                success: function (data) {
                    if(data == "fail"){
                        notify_comm.errorMSG({"message":"账号或密码错误"});
                        return;
                    }
                    //跳转首页
                    location.href = '/indexCtrl/index';
                }
            });

        })
    };
    var _layout = function () {
        $("#layout").on("click",function () {
            $.ajax({
                url: "/login/layout",
                type: "POST",
                async: false,
                dataType: "text",
                data: null,
                success: function (data) {
                    //跳转首页
                    location.href = '/login/login';
                }
            });

        })
    }

    //返回
    return {
        init:init
    }

});